import { createStore } from 'vuex'

export default createStore({
  state: {
    logInfoArray:[],
    logVisible:false,
    trackInfoPath:{},
    userInfoDialogVisible:false,
    trackInfoDialogVisible:false,
    isUpdateRL:false,
    AMap:{},map:{},
    //无人机数组
    aircraft:[],
    //航线任务数组
    flightTasks:[],
    //图片数组
    picArray:[],
    //当前编辑的航线任务
    currentFlightTask:{
      flightTaskId:Number,
      flightTaskName:'',
      defaultVelocity:1,
      defaultHeight:10,
      createTime:{},
      updateTime:{},
    },
    geocoder:{},//位置查询工具
    //地图鼠标工具
    mouseTool:{},
    //地图折线编辑工具 配套折线
    polyEditor:{},polyline:{},
    //右边栏 航线编辑框展示开关
    rightAsideSwitch:false, rightAsideEditorSwitch:true,rightAsideControllerSwitch:false,
    //左边栏 航线任务数组展示开关
    taskListViewSwitch:true,
    //正在编辑的路径 经纬度信息,高度信息,速度信息
    currentPath:[],currentHeight:[],currentVelocity:[],
    //航点编辑窗口开关
    rPointEditDialogSwitch:false,
    //正在编辑的航点的索引
    currentRPointIndex:Number,
    //更新航线任务按钮显示开关,新增航线任务按钮显示开关
    updateTaskButtonSwitch:false,createTaskButtonSwitch:true,
    //正在执行任务的无人机ID,当前正在执行任务的无人机信息
    currentUVAId:-1,currentUVAInfo:{},

  },
  getters:{
    getTrackInfoPath:function (state){
      return state.trackInfoPath;
    },
    getCurrentHeight:function (state){
      return state.currentHeight;
    },
    getCurrentFlightTaskDefaultHeight:function (state){
      return state.currentFlightTask.defaultHeight;
    },
    getCurrentFlightTaskDefaultVelocity:function (state){
      return state.currentFlightTask.defaultVelocity;
    },
    getCurrentRPointIndex:function (state){
      return state.currentRPointIndex;
    },
    getCurrentVelocity:function (state){
      return state.currentVelocity;
    },
    getRPointEditDialogSwitch:function (state){
      return state.rPointEditDialogSwitch;
    },
    getCurrentFlightTask:function (state){
      return state.currentFlightTask;
    },
    getAMap:function (state){
      return state.AMap;
    },
    getTaskListViewSwitch:function (state){
      return state.taskListViewSwitch;
    },
    getRightAsideSwitch:function (state){
      return state.rightAsideSwitch;
    },
    getAircraft:function (state){
      return state.aircraft;
    },
    getMouseTool:function (state){
      return state.mouseTool;
    },
    getPolyEditor:function (state){
      return state.polyEditor;
    }
  },
  mutations: {
    clearAllLog(state){
      state.logInfoArray.splice(0,state.logInfoArray.length);
    },
    addLogInfo(state,payload){
      state.logInfoArray.unshift(new Date().toLocaleString()+':'+payload);
    },
    setLogVisible(state,payload){
      state.logVisible = payload;
    },
    createTrackInfoPath(state,payload){
      state.trackInfoPath = payload;
    },
    setTrackInfoPath(state,payload){
      state.trackInfoPath.setPath(payload);
      state.map.add(state.trackInfoPath)
    },
    setUserInfoDialogVisible(state,payload){
      state.userInfoDialogVisible = payload;
    },
    setTrackInfoDialogVisible(state,payload){
      state.trackInfoDialogVisible = payload;
    },
    setIsUpdateRL(state,payload){
      state.isUpdateRL = payload;
    },
    addPic(state,payload){
      state.picArray.push("data:image/jpg;base64,"+payload);
    },
    setGeocoder(state,payload){
      state.geocoder = payload;
    },
    updateCurrentUVAInfo(state,payload){
      state.currentUVAInfo = payload;
    },
    setCurrentUVAId(state,payload){
      state.currentUVAId = payload;
    },
    updateTaskButtonOnAndOff(state,payload){
      state.updateTaskButtonSwitch = payload;
    },
    createTaskButtonOnAndOff(state,payload){
      state.createTaskButtonSwitch = payload;
    },
    setCurrentFlightTask(state,payload){
      state.currentFlightTask = payload;
    },
    createPolyline(state,payload){
      state.polyline = payload;
    },
    updateFlightTasks(state,payload){
      state.flightTasks = payload;
    },
    setCurrentHeight(state,payload){
      state.currentHeight = payload;
    },
    setCurrentVelocity(state,payload){
      state.currentVelocity = payload;
    },
    setCurrentVelocityOfIndex(state,payload){
      state.currentVelocity[payload.index] = payload.newVelocityOfIndex;
    },
    setCurrentHeightOfIndex(state,payload){
      state.currentHeight[payload.index] = payload.newHeightOfIndex;
    },
    initializeCurrentHeight(state,defaultHeight){
      let len = state.currentPath.length;
      state.currentHeight = [];
      state.currentFlightTask.defaultHeight = defaultHeight;
      for(let i=0;i<len;i++){
        state.currentHeight.push(defaultHeight);
      }
    },
    initializeCurrentVelocity(state,defaultVelocity){
      let len = state.currentPath.length;
      state.currentFlightTask.defaultVelocity = defaultVelocity;
      state.currentVelocity = [];
      for(let i=0;i<len;i++){
        state.currentVelocity.push(defaultVelocity);
      }
    },
    setCurrentFlightTaskDefaultHeight(state,defaultHeight){
      state.currentFlightTask.defaultHeight = defaultHeight;
    },
    setCurrentFlightTaskDefaultVelocity(state,defaultVelocity){
      state.currentFlightTask.defaultVelocity = defaultVelocity;
    },
    setCurrentRPointIndex(state,index){
      state.currentRPointIndex = index;
    },
    rPointEditDialogOnAndOff(state,payload){
      state.rPointEditDialogSwitch = payload;
    },
    updateCurrentPath(state,newPath){
      state.currentPath = newPath;
    },
    clearCurrentFlightTask(state){
      state.currentFlightTask = {};
    },
    setMap(state,map){
      state.map = map;
    },
    setAMap(state,AMap){
      state.AMap = AMap;
    },
    taskListViewOnAndOff(state,payload){
      state.taskListViewSwitch = payload;
    },
    rightAsideOnAndOff(state,payload){
      state.rightAsideSwitch = payload;
    },
    rightAsideEditorOnAndOff(state,payload){
      state.rightAsideEditorSwitch = payload;
    },
    rightAsideControllerOnAndOff(state,payload){
      state.rightAsideControllerSwitch = payload;
    },
    updateAircraft(state, payload){
      state.aircraft = payload;
    },
    createMouseTool(state,payload){
      state.mouseTool = new payload.AMap.MouseTool(payload.map);
    },
    mouseToolDraw(state,AMap){
      state.mouseTool.rule({
        startMarkerOptions: {//可缺省
          icon: new AMap.Icon({
            size: new AMap.Size(19, 31),//图标大小
            imageSize: new AMap.Size(19, 31),
            image: "https://webapi.amap.com/theme/v1.3/markers/b/start.png"
          }),
          offset: new AMap.Pixel(-9, -31),
        },
        endMarkerOptions: {//可缺省
          icon: new AMap.Icon({
            size: new AMap.Size(19, 31),//图标大小
            imageSize: new AMap.Size(19, 31),
            image: "https://webapi.amap.com/theme/v1.3/markers/b/end.png"
          }),
          offset: new AMap.Pixel(-9, -31),
        },
        midMarkerOptions: {//可缺省
          icon: new AMap.Icon({
            size: new AMap.Size(19, 31),//图标大小
            imageSize: new AMap.Size(19, 31),
            image: "https://webapi.amap.com/theme/v1.3/markers/b/mid.png"
          }),
          offset: new AMap.Pixel(-9, -31),
        },
        lineOptions: {//可缺省
          strokeStyle: "solid",
          strokeColor: "#FF33FF",
          strokeOpacity: 1,
          strokeWeight: 2,
        },
      });
    },
    closeMouseToolAndClear(state){
      // console.log("close MouseTool")
      if(state.mouseTool!=null) {
        state.mouseTool.close(true);
      }
    },
    createPolyEditor(state,payload){
      state.polyEditor = new payload.AMap.PolylineEditor(payload.map,null,{
        controlPoint:{
          radius:3
        },
        midControlPoint:{
          radius:2
        }
      });
      state.polyEditor._selectStyle.strokeWeight = 2;
      state.polyEditor._selectStyle.borderWeight = 1;
    },
    closePolyEditor(state){
      // console.log("close PolyEditor")
      state.polyEditor.close();
    }
  },
  actions: {
  },
  modules: {
  }
})
